package com.azt.provider.impl;

import com.azt.api.pojo.EntrustNotes;
import com.azt.api.service.EntrustNotesService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.EntrustNotesMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 委托采购
 * Created by LiQZ on 2017/4/19.
 */
@Service
public class EntrustNotesServiceImpl implements EntrustNotesService {

    @Autowired
    private EntrustNotesMapper entrustNotesMapper;

    @Override
    public Pagination listPage(int pageNo, int pageSize, Map<String, Object> params) {
        Page<Object> startPage = PageHelper.startPage(pageNo, pageSize);
        PageHelper.orderBy("updatetime desc");
        List<EntrustNotes> list = entrustNotesMapper.selectByCondition(params);
        Pagination p = new Pagination(startPage, list);
        p.setList(list);
        return p;
    }

    @Override
    public void save(EntrustNotes req) {
        // 设置默认参数
        if (req.getId() == null) {
            req.setRemoved(0);
            entrustNotesMapper.insert(req);
        } else {
            entrustNotesMapper.updateByPrimaryKeySelective(req);
        }

    }

    @Override
    public void delete(Integer id) {
        EntrustNotes note = new EntrustNotes();
        note.setId(id);
        note.setRemoved(id);
        entrustNotesMapper.updateByPrimaryKeySelective(note);
    }

    @Override
    public EntrustNotes get(Integer id) {
        return entrustNotesMapper.selectNoteAndCompany(id);
    }

}
